﻿Option Explicit On

Public Class frmPhoneAdd
    Public enter_phones As Boolean
    Public phones() As String


    Private Sub frmPhoneAdd_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        enter_phones = False
    End Sub


    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim estates() As String
        Dim ret As New ArrayList
        Dim i As Integer
        Dim value As String = txtEstates.Text
        Dim phone As Object

        'Обрабатываем номера телефонов и проверяем их
        value = value.Trim()
        If value = "" Then Exit Sub
        value = Regex.Replace(value, vbCr, vbLf)
        value = Regex.Replace(value, vbLf & vbLf, vbLf)
        estates = Split(value, vbLf)
        For i = 0 To UBound(estates)
            phone = estates(i).Trim()
            If phone = "" Then Continue For
            phone = getBigPhone(phone)
            phone = getSmallPhone(phone)
            If phone = False Then
                MsgBox("Некоторые выражения не являются телефонами." & vbNewLine & "Проверьте правильность ввода.", MsgBoxStyle.Exclamation)
                Exit Sub
            End If
            ret.Add(phone)
        Next i

        'Если сюда дошли, значит все номера нормальные
        'Заносим массив нормальных телефонов в текстовое поле и выходим из формы
        enter_phones = True
        phones = ret.ToArray(System.Type.GetType("System.String"))
        Me.Hide()
    End Sub


    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        txtEstates.Text = ""
        Me.Hide()
    End Sub
End Class